﻿using MediatR;
using S.Eartag.API.Application.Command.SheepFileConditionCommand;
using S.Eartag.Infrastructure.Impl;
using S.Eartag.Infrastructure.Interface;

namespace S.Eartag.API.Application.CommandHandlers.SheepFileConditionCommandHandler
{
    public class SheepFileConditionAllDeleteCommandHandler : IRequestHandler<SheepFileConditionAllDeleteCommand, int>
    {
        private readonly ISheepFileRepository sheepFileRepository;

        public SheepFileConditionAllDeleteCommandHandler(ISheepFileRepository sheepFileRepository)
        {
            this.sheepFileRepository = sheepFileRepository;
        }

        public async Task<int> Handle(SheepFileConditionAllDeleteCommand request, CancellationToken cancellationToken)
        {
            var Id = request.ids.Split(',').Select(x => Convert.ToInt32(x)).ToArray();
            var list = await sheepFileRepository.GetValues(x => Id.Contains(x.Id));
            foreach (var item in list)
            {
                item.IsDel = true;
            }
            return await sheepFileRepository.UpdateAll(list);
        }
    }
}
